﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Xunit;
using M3G;

namespace MyTestProject {

    public class TestShader {

        /**
         * ファイル名を指定してシェーダーを作成するテスト
         * */
        [Fact]
        public void TestConstructor1 () {
            var shdr = new FragmentShader ("shader/dummy.frag");

            using (FileStream fs = new FileStream ("shader/dummy.frag", FileMode.Open, FileAccess.Read)) {
                var bs = new byte[fs.Length];
                fs.Read (bs, 0, bs.Length);
                var expected = new StreamReader (new MemoryStream (bs)).ReadToEnd ();

                Assert.Equal (expected, shdr.Source);
                Assert.Equal ("Not compiled", shdr.InfoLog);
            }

        }

        /**
         * メモリストリームを指定してシェーダーを作成するテスト
         * */
        [Fact]
        public void TestConstructor2 () {

            using (FileStream fs = new FileStream ("shader/dummy.vert", FileMode.Open, FileAccess.Read)) {

                var bs = new byte[fs.Length];
                fs.Read (bs, 0, bs.Length);

                var shdr     = new VertexShader (new MemoryStream (bs));
                var expected = new StreamReader (new MemoryStream (bs)).ReadToEnd ();

                Assert.Equal (expected, shdr.Source);
                Assert.Equal ("Not compiled", shdr.InfoLog);
            }
        }

        [Fact]
        public void TestDuplicate () {
            var shdr = new FragmentShader ("shader/dummy.frag");
            shdr.UserID = 100;

            var dup = (Shader)shdr.Duplicate ();

            Assert.Equal (shdr.Source, dup.Source);
            Assert.Equal (shdr.InfoLog, dup.InfoLog);
            Assert.Equal (shdr.UserID, dup.UserID);
        }
    }
}
